package com.sky.service.impl;

import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.mapper.UserAddressBookMapper;
import com.sky.service.UserAddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAddressBookServiceImpl implements UserAddressBookService {
    @Autowired
    private UserAddressBookMapper userAddressBookMapper;

    @Override
    public void setAddressBook(AddressBook addressBook) {
        addressBook.setUserId(BaseContext.getCurrentId());
        userAddressBookMapper.add(addressBook);
    }

    @Override
    public List<AddressBook> list(Long currentId) {

        List<AddressBook> list = userAddressBookMapper.list(currentId);


        return list;
    }

    @Override
    public void updateAddressBook(AddressBook addressBook) {
        Long currentId = BaseContext.getCurrentId();
        userAddressBookMapper.updateDefault(currentId);


        addressBook.setIsDefault(1);
        userAddressBookMapper.updateAddressBook(addressBook);
    }

    @Override
    public AddressBook setDefult() {
      AddressBook addressBook=  userAddressBookMapper.setDefult();

        return addressBook;
    }

    @Override
    public AddressBook setById(Long id) {

        AddressBook addressBook = userAddressBookMapper.setById(id);

        return addressBook;
    }

    @Override
    public void DeleteAddressBook(Long id) {
        userAddressBookMapper.DeleteAddressBook(id);
    }
}
